<?php
	
	//add by lin
	
	define('__ROOT__', dirname(dirname(__FILE__)));
	require_once(__ROOT__.'\models\Conn.php'); 
	require_once(__ROOT__.'\models\Emergency.php');
	//end add
	
class EmergencyController extends Controller{

	private $id;

	public function base(){

	}

	public function showList(){

		$e1 = new Emergency();		
		$list = $e1->listAll();
		$arg_item = array();
		foreach( $list as $item )
		{
			array_push($arg_item,implode("/",$item));
		}
		$arg = implode(":",$arg_item);
		header("Location:app/views/emergency.php?list=$arg");
	}
	
	public function showDetail(){
		$e1 = new Emergency();		
		$event_item = $e1->getEvent($this->id);
		$event_process = $e1->getProcess($this->id);
		$event_plan = $e1->getPlan($this->id);
		$event_arg = implode(":",$event_item);
		
		
		$arg_item = array();
		foreach( $event_process as $item )
		{
			array_push($arg_item,implode("/",$item));
		}
		$process_arg = implode(":",$arg_item);
		
		// die();
		
		$arg_item = array();
		foreach( $event_plan as $item )
		{
			array_push($arg_item,implode("~",$item));
		}	
		$plan_arg = implode(":",$arg_item);
		header("Location:app/views/emergency_detail.php?event_item=$event_arg & process_item=$process_arg & plan_item=$plan_arg");
		//header("Location:app/views/emergency_detail.php?event_item=$event_arg & process_item=$process_arg");
	}
	
	// public function editPage()
	// {
		// $id = $this->id;
		// $m1 = new Member();
		// $item = $m1->getById($id);
		// $arg = implode(":",$item);
		// header("Location:app/views/edit_member.php?item=$arg");
	// }
	
	// public function deleteItem()
	// {
		// var_dump('delete');
		// $id = $this->id;
		
		// $m1 = new Member();
		// $m1->delete($id);
		
		// $this->showMemberList();
	// }
	
	// public function addItemPage()
	// {
		// header("Location:app/views/add_member.php");
	// }
	
	// public function addItem()
	// {
		// $new_item_area = $_POST['area'];
		// $new_item_time = $_POST['time'];
		// $new_item_indicator = $_POST['indicator'];
		// $new_item_value = $_POST['value'];
		// $new_item_p5 = $_POST['p5'];
		
		// $item = array("area"=>$new_item_area,"time"=>$new_item_time,"indicator"=>$new_item_indicator,"value"=>$new_item_value,"p5"=>$new_item_p5);
		// $r1 = new Resources();
		// $r1->insert($item);
		// $this->showEconomyList();
	// }
	
	public function setParams($params)
	{
		$this->id = $params[0];
	}
}
